package xing.design.pattern.behavioral.command.sample1;

import xing.design.pattern.behavioral.command.sample1.behavior.Behavior;
import xing.design.pattern.behavioral.strategy.behavior.GoHome;

/**
 * @author xing
 * @date 2023/2/7 22:44:02
 */
public class Person {
    protected Behavior behavior;

    public Person(Behavior behavior) {
        this.behavior = behavior;
    }

    /**
     * protected 关键字：为了不让 strategy 中 的 GoHomePerson 对象被调用时能访问到。
     */
    protected void doSomething() {
        if (this.behavior == null) {
            System.out.println("can't do something.");
            return;
        }
        this.behavior.doSomething();
    }

    protected void setDoSomething(GoHome behavior) {
        this.behavior = behavior;
    }
}
